package indi.kider.server.applet.api;

import indi.kider.common.model.apartment.HouseApplet;
import indi.kider.common.model.apartment.Houses;
import indi.kider.server.applet.model.User;
import indi.kider.server.applet.service.CommService;
import indi.kider.server.applet.service.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;
import indi.kider.common.model.employee.Employee;

import java.util.List;

@RestController
@RequestMapping(value = "enterprise")
public class EnterpriseController {

    @Autowired
    private CommService commService;
    @Autowired
    private EnterpriseService enterpriseService;


    @GetMapping("getEnterprise")
    public CommonResponse<String> getEnterprise() {
        try {
            return CommonResponse.buildGetSuccessResponse(enterpriseService.getEnterprise());
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }

    @PostMapping("getCommunityEnterprise")
    public CommonResponse<Houses> getCommunityEnterprise(@RequestBody HouseApplet houseApplet) {
        try {
            return CommonResponse.buildGetSuccessResponse(enterpriseService.getCommunityEnterprise(houseApplet));
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }


    @PostMapping("getPendingReservation")
    public CommonResponse<Houses> getPendingReservation(@RequestBody User user) {
        try {
            return CommonResponse.buildGetSuccessResponse(enterpriseService.getPendingReservation(user));
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }

    @PostMapping("sameEnterprise")
    public CommonResponse<List<Employee>> sameEnterprise(@RequestBody User user) {
        try {
            return CommonResponse.buildGetSuccessResponse(enterpriseService.getSameEnterprise(user));
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }
}

